package cn.stylefeng.guns.modular.demo.controller;


import cn.stylefeng.guns.dao.service.IAuditLogService;
import cn.stylefeng.guns.dao.service.IAuditNodeService;
import cn.stylefeng.guns.dao.service.impl.AuditLogServiceImpl;
import cn.stylefeng.guns.modular.demo.controller.domain.AuditLogVO;
import cn.stylefeng.guns.modular.demo.controller.domain.AuditQueryRequest;
import cn.stylefeng.guns.modular.demo.controller.domain.AuditRequest;
import cn.stylefeng.guns.modular.demo.controller.domain.SaveAuditLogRequest;
import cn.stylefeng.guns.modular.demo.service.AuditLogBizService;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.annotation.BusinessLog;
import cn.stylefeng.roses.kernel.rule.enums.ResBizTypeEnum;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@ApiResource(name = "核销", resBizType = ResBizTypeEnum.BUSINESS, path = "/audit")
public class AuditLogController {

    @Resource
    private IAuditNodeService auditNodeService;

    @Resource
    private AuditLogBizService auditLogBizService;
    @Resource
    private IAuditLogService auditLogService;


    @PostResource(name = "发起审批", path = "/save", requiredLogin = true, requiredPermission = true)
    @ApiOperation("提交审批")
    @BusinessLog
    public ResponseData<Boolean> save(@RequestBody SaveAuditLogRequest saveAuditLogRequest) {
        auditLogBizService.saveAuditLog(saveAuditLogRequest);

        return new SuccessResponseData<>(true);
    }


    @PostResource(name = "审批单详情", path = "/detail", requiredLogin = true, requiredPermission = true)
    @ApiOperation("提交审批")
    @BusinessLog
    public ResponseData<AuditLogVO> detail(String auditLogId) {
        return new SuccessResponseData<>(auditLogBizService.getDetail(auditLogId));
    }

    @PostResource(name = "审批", path = "/audit", requiredLogin = true, requiredPermission = true)
    @ApiOperation("审批")
    @BusinessLog
    public ResponseData<Boolean> audit(@RequestBody AuditRequest auditRequest) {
        auditLogBizService.audit(auditRequest);
        return new SuccessResponseData<>(true);
    }

    @PostResource(name = "查询审批数据", path = "/page", requiredLogin = true, requiredPermission = true)
    @ApiOperation("查询审批数据")
    public ResponseData<PageResult<AuditLogVO>> list(@RequestBody AuditQueryRequest auditRequest) {

        PageResult<AuditLogVO> page = auditLogBizService.getPage(auditRequest);
        return new SuccessResponseData<>(page);
    }


}
